﻿@{
    Layout = null;
}
<script type="text/javascript">
    //树
    var zNodes_permission_duty_DutyTree = [];
    var zTree_permission_duty_DutyTree;
    var setting_permission_duty_DutyTree;
    var deleteID_permission_duty_DutyTree = false;
    var rootNodeId_permission_duty_DutyTree = "0"; //记录根节点id
    //全局的href
    var href_permission_duty_DutyTree = "/Permission/Duty";
    setting_permission_duty_DutyTree = {
        checkable: false,
        async: true,
        isSimpleData: true,
        editable: false,
        asyncUrl: "/Permission/Duty/GetDutyNodes",  //获取节点数据的URL地址
        nameCol: "Name",
        open: false,
        treeNodeKey: "ID",
        treeNodeParentKey: "ParentId",
        callback: {
            //             beforeAsync: zTreeBeforeAsync,
            asyncSuccess: zTreeOnAsyncSuccess_permission_duty_DutyTree,
            //             asyncError: zTreeOnAsyncError,
            click: zTreeOnClick_permission_duty_DutyTree
        }
    };

    function zTreeOnAsyncSuccess_permission_duty_DutyTree(event, treeId, treeNode, msg) {
        //异步成功
    }
    //树的单击事件
    function zTreeOnClick_permission_duty_DutyTree(event, treeId, treeNode) {
        if (treeNode.ID != 0) {//点的不是根节点
            deleteID_permission_duty_DutyTree = true; //选中节点
            var nodeId = treeNode.ID;

        }
    }

    $(document).ready(function () {
        refreshTree("/Permission/Duty/GetDutyNodes");
    });



    function refreshTree(asyncUrl) {
        $("#getUrl").html("");
        $("#onAsyncSuccessNode").html("<br/>");
        $("#onAsyncErrorNode").html("<br/>");
        setting_permission_duty_DutyTree.asyncUrl = asyncUrl;
        if ((typeof asyncUrl) == "function") {
            $("#asyncUrlCode").html("setAsyncUrl");
        } else {
            $("#asyncUrlCode").html("\"" + asyncUrl + "\"");
        }
        zTree_permission_duty_DutyTree = $("#treeduty_permission_duty_DutyTree").zTree(setting_permission_duty_DutyTree, zNodes_permission_duty_DutyTree);

    }

    $("#btnSave_Permission_Duty_SelectDuty").click(function () {
        if (!deleteID_permission_duty_DutyTree) {//如果没有选择节点就不能点击确定按钮
            alertMsg.error("请选择节点！");
            return false;
        }
        var selectedNode = zTree_permission_duty_DutyTree.getSelectedNode();
        //岗位部门挂接
        $.post("/Permission/Organize/CreateConnectionOrgAndDuty", { orgId: $("#parentId_permission_duty_DutyTree").val(), dutyId: selectedNode.ID, dutyName: selectedNode.Name }, dialogAdded_Permission_Organize, "json");
    });
</script>
<div class="pageContentD">
    <div class="pageContent" layouth="40">
        <ul class="searchBar">
            <li>
                <span>所属部门：</span>
                <i style="width:145px;text-overflow:ellipsis;white-space:nowrap;overflow:hidden;" title=@ViewBag.Name>@ViewBag.Name</i>
                <input type="hidden" id="parentId_permission_duty_DutyTree" name="ParentId" value="@ViewBag.ID" />
                <input type="hidden" name="SelectedID" />
            </li>
        </ul>
        <div layouth="85">
            <ul id="treeduty_permission_duty_DutyTree" class="ztree">
            </ul>
        </div>
        
    </div>
    <div class="formBar">
        <ul>
            <li>
                <button type="button" class="btn btn-success btn-sm" id="btnSave_Permission_Duty_SelectDuty">
                    确定</button>
            </li>
            <li>
                <button type="button" class="close btn btn-default btn-sm">
                    取消</button>
            </li>
        </ul>
    </div>
</div>
